var $$$={
	keywords:{ // change these to suit your style
		_class:   'Class',
		_extends: 'Extends',
		_static:  'Static',
		_module:  'Module',
		_require: 'Require'
	},
	version: '1.0'
}
window[$$$.keywords._class] = function(name){
	return function(def){
		
		if(/\./.test(name)){
			var x = name.split('.'), c = x.pop();
			return window[$$$.keywords._module](x.join('.'))(function(){
				window[$$$.keywords._class](c)(def);
			})
		}
		
		var Scope = window._currentScope || window,
	    	Super = Scope[def[$$$.keywords._extends]] || window[def[$$$.keywords._extends]];
		// if(!Super && def[$$$.keywords._extends]) with(Scope){
		// 			console.log('I WAS CALLED')
		// 			Super = eval(def[$$$.keywords._extends])
		// 		}
		var fixSuper = function(func, prop){
			if(Scope!=window){
				func = Function("s","with(s) return ("+func+")")(Scope)
			}
			if(!Super || !(/\bthis\.Super\b/).test(String(func))){
				return func;
			}
			return function(){
				var lastSuper = this.Super;
				this.Super    = prop? Super.prototype[prop] : Super;
				var returnObj = func.apply(this,arguments);
				this.Super    = lastSuper;
				return returnObj;
			}
		}
		var constructor = fixSuper(def[name]);
		var klass = Scope[name] = function(){
			if(this._isPrototyping) return;
			if(constructor) return constructor.apply(this,arguments);
		}
		klass.toString = function(){
			return String(constructor)
		}
		if(Super){
			Super.prototype._isPrototyping = true;
			klass.prototype = new Super;
			delete Super.prototype._isPrototyping;
		}
		klass.prototype.toString = klass.toString;
		for(var i in def){
			if( i != name && i != $$$.keywords._extends ){
				if( i == $$$.keywords._static ){
					for(var j in def[i]){
						klass[j] = def[i][j];
					}
				}
				else{
					klass.prototype[i] = def[i] instanceof Function?
					fixSuper( def[i], i ) : def[i];
				}
			}
		}
	}
}
window[$$$.keywords._module] = function(name){
	return function(def){
		
		if(/\./.test(name)){
			var x = name.split('.');
			return window[$$$.keywords._module](x.shift())(function(){
				window[$$$.keywords._module](x.join('.'))(def);
			})
		}

		var scope = window._currentScope || window;
		scope[name] = scope[name] ? scope[name] : {};
		window._currentScope = scope[name];
		if(def instanceof Function){
			def();
		}
		else{
			for(var i in def){
				scope[name][i] = def[i];
			}
		}
		// reset the scope
		window._currentScope = scope!=window?scope:null;
		
	}
}


window[$$$.keywords._require] = function(req){
	if(arguments.length>1){
		for(var i in arguments) this(i)
	}
	var head = document.getElementsByTagName("head").item(0);
	var URL  = req.replace(/\./g,'/') + '.js';
	var ID   = req.replace(/\./g,'_');
	var scr  = document.createElement("script");
	var date = new Date();
	scr.setAttribute("src", URL + "?rf=" + date.getTime());
	scr.setAttribute("id", ID);
	head.appendChild(scr);
	// we can't load the requested Class
	scr.onerror = function(){
		console.log('Class: '+req+' could not be found.');
	}
}